#ifndef __MPI_JPEG_ENCODER_H__
#define __MPI_JPEG_ENCODER_H__

#include "rk_mpi.h"

class MpiJpegEncoder {
public:
    MpiJpegEncoder();
    ~MpiJpegEncoder();

    // Supported lists for InputFormat
    typedef enum {
        INPUT_FMT_YUV420SP      = MPP_FMT_YUV420SP,
        INPUT_FMT_YUV420P       = MPP_FMT_YUV420P,
        INPUT_FMT_YUV422SP_VU   = MPP_FMT_YUV422SP_VU,
        INPUT_FMT_YUV422_YUYV   = MPP_FMT_YUV422_YUYV,
        INPUT_FMT_YUV422_UYVY   = MPP_FMT_YUV422_UYVY,
        INPUT_FMT_RGB888        = MPP_FMT_RGB888,
        INPUT_FMT_BGR888        = MPP_FMT_BGR888,
    } InputFormat;

    typedef struct {
        uint8_t *data;
        int size;
    } OutputPacket_t;

    typedef struct {
        /* input buffer information */
        int inputPhyAddr;
        unsigned char* inputVirAddr;
        int inputWidth;
        int inputHeight;

        /* output buffer information */
        int outputPhyAddr;
        unsigned char* outputVirAddr;
        int outputFileLen;

        /* coding quality - range from (1 - 10) */
        int qLvl;

        /* dimension parameter for thumbnail */
        int thumbWidth;
        int thumbHeight;

        /* Exif information */
        void *exifInfo;
    } JpegEncTask;

    bool prepareEncoder();
    void flushBuffer();
    bool updateEncodeCfg(int width, int height,
                         InputFormat fmt = INPUT_FMT_YUV420SP);

    bool encodeFrame(char *data, OutputPacket_t *aPktOut);
    bool encodeFile(const char *input_file, const char *output_file);
    bool encodeTask(JpegEncTask task);

private:
    MppCtx          mpp_ctx;
    MppApi          *mpi;

    int             initOK;

    /*
     * Format of the raw input data for encode
     */
    int             mInputWidth;
    int             mInputHeight;
    InputFormat     mInputFmt;

    MppBufferGroup  mFrameGroup;

    /* Dump input & output for debug */
    FILE            *fp_input;
    FILE            *fp_output;
};

#endif  // __MPI_JPEG_ENCODER_H__
